﻿using System;
using System.Windows;
using jSLApp.Client.ApplicationBase;
using jSLApp.Client.MainService;
using jSLCore.Client.Presentation.BaseControl;

namespace jSLApp.Client.Forms
{
    public partial class MessageDetail : DialogControl
    {
        private readonly int _messageId;

        public MessageDetail(int messageId):this()
        {
            _messageId = messageId;
        }

        /// <summary>
        /// only for designers
        /// </summary>
        public MessageDetail()
        {
            InitializeComponent();
        }

        public override void LoadInitialData()
        {
            DoWork("Загрузка сообщения",(sender, args) =>
                                            {
                                                args.Result = Communication.Proxy.GetUserMessage(args.Int);
                                            },(o, eventArgs) =>
                                                                  {
                                                                      if(eventArgs.Error==null)
                                                                      {
                                                                          SetDataContext((Message) eventArgs.Result);
                                                                      }
                                                                  },_messageId);
        }


        public void SetDataContext(Message message)
        {
            Message = message;
            
            Bind();
        }

        public Message Message
        {
            get { return (Message) DataContext; }
            set { DataContext = value; }
        }

        #region dialog

        public override bool AutoSize
        {
            get { return true; }
        }

        public override bool IsStandartOkCancelEnabled
        {
            get { return true; }
        }

        public override object CancelContent
        {
            get { return "Закрыть"; }
        }

        public override bool IsOkVisible
        {
            get { return false; }
        }

        #endregion

        private void goSender(object sender, RoutedEventArgs e)
        {
            MainContentContainer.Current.GotoUserAbout(Message.From);
        }

        private void goRecep(object sender, RoutedEventArgs e)
        {
            MainContentContainer.Current.GotoUserAbout(Message.To);
        }

        private void Reply(object sender, RoutedEventArgs e)
        {
            var dlg = new NewMessage(Message.id);
            dlg.ShowDialog(this);
            InvokeCancelSelected();
        }
    }
}
